//
//  Util.m
//  QBPatient
//
//  Created by 阳光 on 16/8/3.
//  Copyright © 2016年 QB. All rights reserved.
//

#import "Util.h"


@implementation Util

+(BOOL)saveObjectToUserDefault:(id)object forKey:(NSString *)key
{
    NSUserDefaults *defaults=[NSUserDefaults standardUserDefaults];
    [defaults setObject:object forKey:key];
    return [defaults synchronize];
}

+(id)getUserDefaultObjectForKey:(NSString *)key
{
    id object=[[NSUserDefaults standardUserDefaults] objectForKey:key];
    return object==nil?@"":object;
}


//根据编码 修改项目名称
+(NSString *)changCodeToName:(NSString *)code
{
    // 打针
    if ([code isEqualToString:@"DA_injection"])
    {
        return NSLocalizedString(@"Injection", nil);//@"打针";
    }
    // 吃药
    else if ([code isEqualToString:@"DA_medicine"])
    {
        return NSLocalizedString(@"Take Medicine", nil);//@"吃药";
    }
    // B超
    else if ([code isEqualToString:@"DA_bultra"])
    {
        return NSLocalizedString(@"B Ultrasound", nil);//@"B超";
    }
    // 验血
    else if ([code isEqualToString:@"DA_bloodtest"])
    {
        return NSLocalizedString(@"Blood Test", nil);//@"验血";
    }
    // 取卵
    else if ([code isEqualToString:@"DA_ovumpick"])
    {
        return NSLocalizedString(@"Ovum Pick", nil);//@"取卵";
    }
    // 取精
    else if ([code isEqualToString:@"DA_sperm"])
    {
        return NSLocalizedString(@"Sperm Pick", nil);//@"取精";
    }
    // 移植
    else if ([code isEqualToString:@"DA_transplant"])
    {
        return NSLocalizedString(@"Transfer", nil);//@"移植";
    }
    return nil;
}


// 根据编码 修改药品
+(NSString *)changDrugCodeToName:(NSString *)code
{
    if ([code isEqualToString:@"201"])
    {
        return NSLocalizedString(@"Cetrotide", nil);//@"思则凯";
    }
    else if ([code isEqualToString:@"202"])
    {
        return NSLocalizedString(@"Luveris", nil);//@"乐芮";
    }
    else if ([code isEqualToString:@"203"])
    {
        return NSLocalizedString(@"EstradiolGel", nil);//@"爱斯妥";
    }
    else if ([code isEqualToString:@"204"])
    {
        return NSLocalizedString(@"Crinone", nil);//@"雪诺酮";
    }
    else if ([code isEqualToString:@"205"])
    {
        return @"黄体酮注射剂";
    }
    else if ([code isEqualToString:@"206"])
    {
        return NSLocalizedString(@"Diphereline", nil);//@"达菲林";
    }
    else if ([code isEqualToString:@"207"])
    {
        return NSLocalizedString(@"Decapepthl", nil);//@"达必佳";
    }
    else if ([code isEqualToString:@"208"])
    {
        return @"天兴";
    }
    else if ([code isEqualToString:@"209"])
    {
        return NSLocalizedString(@"Gonal-f", nil);//@"果纳芬";
    }
    else if ([code isEqualToString:@"210"])
    {
        return @"丽申宝";
    }
    else if ([code isEqualToString:@"211"])
    {
        return NSLocalizedString(@"Puregon", nil);//@"普丽康";
    }
    else if ([code isEqualToString:@"212"])
    {
        return NSLocalizedString(@"Fostimen", nil);//@"福特蒙";
    }
    else if ([code isEqualToString:@"213"])
    {
        return NSLocalizedString(@"Menopur", nil);//@"贺美奇";
    }
    else if ([code isEqualToString:@"214"])
    {
        return NSLocalizedString(@"Clomiphene", nil);//@"克罗米芬";
    }
    else if ([code isEqualToString:@"215"])
    {
        return NSLocalizedString(@"Letrozole", nil);//@"来曲唑";
    }
    else if ([code isEqualToString:@"216"])
    {
        return NSLocalizedString(@"EstradiolValerate Tablets", nil);//@"补佳乐";
    }
    else if ([code isEqualToString:@"217"])
    {
        return NSLocalizedString(@"Progesterone Capsules", nil);//@"安琪坦";
    }
    else if ([code isEqualToString:@"218"])
    {
        return NSLocalizedString(@"Dydrogesterone Tablets", nil);//@"达芙通";
    }
    return nil;
}

//根据编码 修改药品数量
+ (NSString *)changHowMuchCodeToName:(NSString *)code
{
    // 一支
    if ([code isEqualToString:@"301"])
    {
        return NSLocalizedString(@"1 dose", nil);//@"1支";
        
    }
    else if([code isEqualToString:@"302"])
    {
        return NSLocalizedString(@"2 dose", nil);//@"2支";
    }
    else if ([code isEqualToString:@"303"])
    {
        return NSLocalizedString(@"3 dose", nil);//@"3支";
    }
    else if ([code isEqualToString:@"304"])
    {
        return NSLocalizedString(@"4 dose", nil);//@"4支";
    }
    else if ([code isEqualToString:@"305"])
    {
        return NSLocalizedString(@"1/4 tablet", nil);//@"4分之一片";
    }
    else if ([code isEqualToString:@"306"])
    {
        return NSLocalizedString(@"1/2 tablet", nil);//@"2分之一片";
    }
    else if ([code isEqualToString:@"307"])
    {
        return NSLocalizedString(@"1 tablet", nil);//@"1片";
    }
    else if ([code isEqualToString:@"308"])
    {
        return NSLocalizedString(@"2 tablet", nil);//@"2片";
    }
    else if ([code isEqualToString:@"309"])
    {
        return NSLocalizedString(@"3 tablet", nil);//@"3片";
    }
    else if ([code isEqualToString:@"310"])
    {
        return NSLocalizedString(@"4 tablet", nil);//@"4片";
    }
    return nil;
}


// 根据编码 修改项目名称 反向
+(NSString *)changNameToCode:(NSString *)name
{
    // 打针
    if ([name isEqualToString:NSLocalizedString(@"Injection", nil)])//@"打针"
    {
        return @"DA_injection";
    }
    // 吃药
    else if ([name isEqualToString:NSLocalizedString(@"Take Medicine", nil)])//@"吃药"
    {
        return @"DA_medicine";
    }
    // B超
    else if ([name isEqualToString:NSLocalizedString(@"B Ultrasound", nil)])//@"B超"
    {
        return @"DA_bultra";
    }
    // 验血
    else if ([name isEqualToString:NSLocalizedString(@"Blood Test", nil)])//@"验血"
    {
        return @"DA_bloodtest";
    }
    // 取卵
    else if ([name isEqualToString:NSLocalizedString(@"Ovum Pick", nil)])//@"取卵"
    {
        return @"DA_ovumpick";
    }
    // 取精
    else if ([name isEqualToString:NSLocalizedString(@"Sperm Pick", nil)])//@"取精"
    {
        return @"DA_sperm";
    }
    // 移植
    else if ([name isEqualToString:NSLocalizedString(@"Transfer", nil)])//@"移植"
    {
        return @"DA_transplant";
    }
    
    return nil;
}


//根据编码 修改药品 反向
+(NSString *)changNameToDrugCode:(NSString *)name
{
    if ([name isEqualToString:NSLocalizedString(@"Cetrotide", nil)])//@"思则凯"
    {
        return @"201";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Luveris", nil)])//@"乐芮"
    {
        return @"202";
    }
    else if ([name isEqualToString:NSLocalizedString(@"EstradiolGel", nil)])//@"爱斯妥"
    {
        return @"203";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Crinone", nil)])//@"雪诺酮"
    {
        return @"204";
    }
    else if ([name isEqualToString:@"黄体酮注射剂"])
    {
        return @"205";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Diphereline", nil)])//@"达菲林"
    {
        return @"206";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Decapepthl", nil)])//@"达必佳"
    {
        return @"207";
    }
    else if ([name isEqualToString:@"天兴"])
    {
        return @"208";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Gonal-f", nil)])//@"果纳芬"
    {
        return @"209";
    }
    else if ([name isEqualToString:@"丽申宝"])
    {
        return @"210";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Puregon", nil)])//@"普丽康"
    {
        return @"211";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Fostimen", nil)])//@"福特蒙"
    {
        return @"212";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Menopur", nil)])//@"贺美奇"
    {
        return @"213";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Clomiphene", nil)])//@"克罗米芬"
    {
        return @"214";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Letrozole", nil)])//@"来曲唑"
    {
        return @"215";
    }
    else if ([name isEqualToString:NSLocalizedString(@"EstradiolValerate Tablets", nil)])//@"补佳乐"
    {
        return @"216";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Progesterone Capsules", nil)])//@"安琪坦"
    {
        return @"217";
    }
    else if ([name isEqualToString:NSLocalizedString(@"Dydrogesterone Tablets", nil)])//@"达芙通"
    {
        return @"218";
    }
    return nil;
}

//根据编码 修改药品数量 反向
+ (NSString *)changNameToHowMuchCode:(NSString *)name
{
    if ([name isEqualToString:NSLocalizedString(@"1 dose", nil)])//@"1支"
    {
        return @"301";
    }
    else if ([name isEqualToString:NSLocalizedString(@"2 dose", nil)])//@"2支"
    {
        return @"302";
    }
    else if ([name isEqualToString:NSLocalizedString(@"3 dose", nil)])//@"3支"
    {
        return @"303";
    }
    else if ([name isEqualToString:NSLocalizedString(@"4 dose", nil)])//@"4支"
    {
        return @"304";
    }
    else if ([name isEqualToString:NSLocalizedString(@"1/4 tablet", nil)])//@"4分之一片"
    {
        return @"305";
    }
    else if ([name isEqualToString:NSLocalizedString(@"1/2 tablet", nil)])//@"2分之一片"
    {
        return @"306";
    }
    else if ([name isEqualToString:NSLocalizedString(@"1 tablet", nil)])//@"1片"
    {
        return @"307";
    }
    else if ([name isEqualToString:NSLocalizedString(@"2 tablet", nil)])//@"2片"
    {
        return @"308";
    }
    else if ([name isEqualToString:NSLocalizedString(@"3 tablet", nil)])//@"3片"
    {
        return @"309";
    }
    else if ([name isEqualToString:NSLocalizedString(@"4 tablet", nil)])//@"4片"
    {
        return @"310";
    }
    return nil;
}




// 时间戳转时间
+(NSString *)getConvertToDateByTimeStamp:(NSString *)timeStamp
{
    
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    NSTimeZone* timeZone=[NSTimeZone systemTimeZone];
    [formatter setTimeZone:timeZone];
    [formatter setDateFormat:@"YYYY-MM-dd"];
    // YYYY-MM-dd HH:mm  YYYY-MM-dd
    
    NSDate * currentDate=[NSDate dateWithTimeIntervalSince1970:[timeStamp longLongValue]];
    NSString * formDateStr=[formatter stringFromDate:currentDate];
//    NSLog(@"Time :%@",formDateStr);
    
    return formDateStr;
}

// 时间戳转时间正常显示
+(NSString *)getConvertToFormalDateByTimeStamp:(NSString *)timeStamp
{
    
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    
    NSTimeZone* timeZone=[NSTimeZone systemTimeZone];
    [formatter setTimeZone:timeZone];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm"];
    // YYYY-MM-dd HH:mm  YYYY-MM-dd
    
    NSDate * currentDate=[NSDate dateWithTimeIntervalSince1970:[timeStamp longLongValue]];
    NSString * formDateStr=[formatter stringFromDate:currentDate];
    // NSLog(@"formDateStr :%@",formDateStr);
    
    return formDateStr;
}

// 时间转时间戳
+(NSString *)getTimeStampByDate:(NSString *)timeStr
{
    
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm"];
    
    NSDate *firstTimeDate=[formatter dateFromString:timeStr];
    NSString *firstTimeSp=[NSString stringWithFormat:@"%ld",(long)[firstTimeDate timeIntervalSince1970]];
    //NSLog(@"TimeSp :%@", firstTimeSp);
    
    return firstTimeSp;
}

// 时间正常显示转时间戳
+(NSString *)getTimeStampByFormalDate:(NSString *)timeStr
{
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm"];
    
    NSDate *firstTimeDate=[formatter dateFromString:timeStr];
    NSString *firstTimeSp=[NSString stringWithFormat:@"%ld",(long)[firstTimeDate timeIntervalSince1970]];
    //NSLog(@"TimeSp :%@", firstTimeSp);
    
    return firstTimeSp;
}


//获取当前时间戳
+(NSString *)getNowTime
{
    
    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    [dateformatter setDateStyle:NSDateFormatterMediumStyle];
    [dateformatter setTimeStyle:NSDateFormatterShortStyle];
    [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSString *date1 = [dateformatter stringFromDate:[NSDate date]];
    //NSLog(@"date1 :%@", date1);
    
    NSDate *firstTimeDate=[dateformatter dateFromString:date1];
    NSString *firstTimeSp=[NSString stringWithFormat:@"%ld",(long)[firstTimeDate timeIntervalSince1970]];
    //NSLog(@"nowTimeSp :%@", firstTimeSp);
    
    return firstTimeSp;
}

//获取今日结束时间戳
+(NSString *)getTodayEndTime
{
    
    NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];
    [dateformatter setDateStyle:NSDateFormatterMediumStyle];
    [dateformatter setTimeStyle:NSDateFormatterShortStyle];
    [dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    
    NSString *date1 = [dateformatter stringFromDate:[NSDate date]];
    NSArray *temp=[date1 componentsSeparatedByString:@" "];
    NSString *end=[NSString stringWithFormat:@"%@ 23:59:59",temp[0]];
    //NSLog(@"endTime :%@", end);
    
    return [Util getTimeStampByDate:end];
    
}

@end
